from __future__ import absolute_import

import os
import datetime

from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bookloft.settings')

from django.conf import settings  # noqa

app = Celery('bookloft')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
# app.conf.update(
#    CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
#)
# app.conf.update(
#    CELERY_RESULT_BACKEND='djcelery.backends.cache:CacheBackend',
#)
# app.conf.CELERY_TASK_SERIALIZER = 'yaml'
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

from celery.schedules import crontab

app.conf.update({
    # Executes every Monday morning at 12:30 a.m.
    # 'ready_cron': {
    #     'task': 'blog.tasks.ready_cron',
    #     'schedule': crontab(hour=12, minute=30, day_of_week=1),
    #     'args': (16, 16),
    # },
    'CELERYBEAT_SCHEDULE': {
        'ready_cron': {
            'task': 'blog.tasks.ready_cron',
            'schedule': datetime.timedelta(hours=1),
        },
        'handle_cron': {
            'task': 'blog.tasks.handle_cron',
            'schedule': datetime.timedelta(minutes=13),
        },
        'touch_new_erp': {
            'task': 'common.tasks.touch_new_erp',
            'schedule': datetime.timedelta(minutes=25),
        },
    }
})



@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))
